package com.atguigu.gmall.controller;

import com.atguigu.gmall.activity.client.SeckillFeignClient;
import com.atguigu.gmall.model.activity.SeckillGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * @author: 封捷
 * @create-date: 2022/9/18 17:19
 */
@Controller
public class ActivityController {

    @Autowired
    private SeckillFeignClient seckillFeignClient;

    @RequestMapping("/seckill.html")
    public String toSeckillListPage(Model model) {

        List<SeckillGoods> seckillGoodsList = seckillFeignClient.getAllSeckillGoods().getData();

        model.addAttribute("list", seckillGoodsList);

        return "seckill/index";
    }

    @RequestMapping("/seckill/{skuId}.html")
    public String toSeckillDetailPage(@PathVariable("skuId") Long skuId, Model model) {

        SeckillGoods seckillGoods = seckillFeignClient.getSecKillGoodsBySkuId(skuId).getData();

        model.addAttribute("item", seckillGoods);

        return "seckill/item";
    }

    @RequestMapping("/seckill/queue.html")
    public String toQueuePage(
            @RequestParam("skuId") Long skuId,
            @RequestParam("skuIdStr") String skuIdStr, Model model) {

        model.addAttribute("skuId", skuId);
        model.addAttribute("skuIdStr", skuIdStr);

        return "seckill/queue";
    }

    @RequestMapping("/seckill/trade.html")
    public String toTradePage(Model model) {

        Map<String, Object> resultMap = seckillFeignClient.getDataForTrade().getData();

        model.addAllAttributes(resultMap);

        return "seckill/trade";
    }
}
